import Mock from 'mockjs';
import subAssetsJson from '../../data/audit/subAssets.json';


export default {
    className: "media.model.SubAssets",
    queryData: function(postData) {
        console.log(postData);
        var result=[];
        var j = 0;
        for (var i = 0; i < subAssetsJson.length; i++) {
            if (postData.condition.assetName.val == subAssetsJson[i].assetName) {
                // if(subAssetsJson[i].itemTitle.indexOf('_')>0){
                //     subAssetsJson[i].itemNum = subAssetsJson[i].itemTitle.split('_')[1];
                // }
                result[j] = subAssetsJson[i];
                j++;
            }
        }
        return Mock.mock({
            isSuccess: "Y",
            reason: "",
            message: [],
            "data": {
                "recordCount": 38,
                "pageCount": 1,
                "pageIndex": 1,
                "pageSize": 20,
                // "queryResult|38": [{
                //     "keyID|1000-9999": 1000,
                //     "assetsNo": /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/,
                //     "assetsName": Mock.mock('@ctitle'),//@title为英文版
                //     "type": Mock.mock('@ctitle'),
                //     "source": Mock.mock('@ctitle'),
                //     "count": /^[0-9][0-9]$/,
                //     "highDefinition": '是',
                //     "status": Mock.mock('@ctitle'),
                //     "auditTime": Mock.mock('@now'),
                //     "version": 1
                // }],
                // "queryResult": assetsAuditJson,
                "queryResult": result
            }
        });
    },
    queryByKeyID: function(postData) {

        var curFindObject = null;
        for (var i = 0; i < subAssetsJson.length; i++) {
            if (postData.keyID == subAssetsJson[i].keyID) {
                curFindObject = subAssetsJson[i];
                break;
            }
        }
        if (curFindObject == null) {
            return Mock.mock({
                isSuccess: "Y",
                reason: "",
                message: [],
                "data": {
                    "keyID|1000-9999": 1000,
                    "assetsNo": /^[A-Z][a-z][a-z][0-9][a-z][A-Z][a-z][0-9][a-z][a-z]$/,
                    "assetsName": Mock.mock('@ctitle'),//@title为英文版
                    "type": Mock.mock('@ctitle'),
                    "source": Mock.mock('@ctitle'),
                    "itemNum": /^[0-9][0-9]$/,
                    "definition": Mock.mock('@ctitle'),
                    "status": Mock.mock('@ctitle'),
                    "createTime": Mock.mock('@now'),
                    "version": 1
                }
            });
        } else {
            return {
                isSuccess: "Y",
                reason: "",
                message: [],
                data: curFindObject,
            };
        }

        
    },
};
